#pragma once
#include <vector>
#include <functional>
#include <mutex> 

template <class T> 
class EventQueue
{ 
public:
    typedef  std::function<void(T )> Processor; 
    void push(T item)
    {
        std::lock_guard<std::mutex> guard(m_mutex);
        m_data.push_back(item); 
    }

    // single thread 
    void process(Processor processor)
    {
        //static std::vector<T> m_cache; 
        {
            std::lock_guard<std::mutex> guard(m_mutex);
            m_data.swap(m_cache);
        }

        for(auto item : m_cache)
        {
            processor(item); 
        } 
        m_cache.clear(); 
    }
  
private: 
    std::mutex  m_mutex; 
    std::vector<T> m_data;  
    std::vector<T> m_cache;  
}; 


